import Vue from 'vue'

import 'normalize.css/normalize.css' // A modern alternative to CSS resets

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import locale from 'element-ui/lib/locale/lang/zh-CN' // lang i18n

import '@/styles/index.scss' // global css

import App from './App'
import store from './store'
import router from './router'

import '@/icons' // icon
import '@/permission' // permission control
import Viewer from 'v-viewer';
import 'viewerjs/dist/viewer.css';
// 阿里图标
import "@/assets/font/iconfont.js";
import "@/assets/font/iconfont.css";
Vue.use(Viewer);  // 使用 v-viewer 插件
/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online ! ! !
 */
if (process.env.NODE_ENV === 'production') {
  const { mockXHR } = require('../mock')
  mockXHR()
}
function autoRefreshAtMidnight() {
  // 获取当前时间
  const now = new Date();

  // 设置下一个凌晨时间点 (明天的 00:00)
  const tomorrow = new Date(now);
  tomorrow.setDate(tomorrow.getDate() + 1);
  tomorrow.setHours(0, 0, 0, 0);

  // 计算距离下一个凌晨的毫秒数，向上取整到分钟
  const timeUntilMidnight = Math.ceil((tomorrow - now) / 60000) * 60000;

  // 设置定时器，在凌晨时刷新页面
  setTimeout(() => {
    window.location.reload();
    // 重新设置下一天的定时器
    autoRefreshAtMidnight();
  }, timeUntilMidnight);

  // 输出下次刷新时间（用于调试）
  console.log('下次页面刷新时间：', tomorrow.toLocaleString('zh-CN', {
    year: 'numeric',
    month: '2-digit',
    day: '2-digit',
    hour: '2-digit',
    minute: '2-digit'
  }));
}

// 启动自动刷新
autoRefreshAtMidnight();

// set ElementUI lang to EN
Vue.use(ElementUI, { locale })
// 如果想要中文版 element-ui，按如下方式声明
// Vue.use(ElementUI)

Vue.config.productionTip = false

new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App)
})
